#include <sys/types.h>
#include <dirent.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

int main(int argc, const char *argv[])
{
    DIR *dirp;
    struct dirent *dt;
    // 1.校验输入成员的个数
    if (argc != 2)
    {
        fprintf(stderr, "input error,try again\n");
        fprintf(stderr, "usage:./%s dirname\n",__FILE__);
        return -1;
    }
    // __FILE__
    // 2.打开目录
    if ((dirp = opendir(argv[1])) == NULL)
        perror("open dir error");
    // PRINT_ERR("open dir error");

    // 3.读取目录下的内容
    while ((dt = readdir(dirp)) != NULL)
    {
        switch (dt->d_type)
        {
        case DT_BLK:
            printf("这是块设备文件\n");
            break;
        case DT_CHR:
            printf("这是块设备文件\n");
            break;
        case DT_DIR:
            printf("这是目录文件\n");
            break;
        case DT_FIFO:
            printf("这是管道文件文件\n");
            break;
        case DT_LNK:
            printf("这是软连接文件\n");
            break;
        case DT_REG:
            printf("这是普通文件 ");
            break;
        case DT_SOCK:
            printf("这是套接字文件 ");
            break;
        }

        printf("name =[%s],ino=%ld,size = %d\n", dt->d_name, dt->d_ino, dt->d_reclen);
    }

    closedir(dirp);
    return 0;
}